package edu.hit.pact.pgse.crawler.bbs;

import java.util.ArrayList;
import java.util.HashMap;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Hashtable;

 public class BBSURL {
	
	
    private URL url;
    private HashMap<String ,String> params = new HashMap<String,String>();;
    private String[] paths;
    
	
	public BBSURL() {
		super();
	}


	public BBSURL(URL url) {
		super();
		this.url = url;
	}
    
	
	
 	public BBSURL(String url) {
		super();
		try {
			this.url = new URL(url);
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}


	public BBSURL(URL url, HashMap<String, String> params) {
		super();
		this.url = url;
		this.params = params;
	}


	public URL getUrl() {
		return url;
	}

	public void setUrl(URL url) {
		this.url = url;
	}

	
	public HashMap<String, String> getParams() {
		return params;
	}


	public void setParams(HashMap<String, String> params) {
		this.params = params;
	}


	public String[] getPaths() {
		return paths;
	}


	public void setPaths(String[] paths) {
		this.paths = paths;
	}


	public void extractQuery()
	{
		String query = url.getQuery();
		if(query != null)
		{
			String[] subQuery = query.split("&");
			if(subQuery == null)
				return;
			for (String item : subQuery) {
				if (item == null || item == " ")
					return;
				String[] args = item.split("=");
				if(args == null || args.length < 2)
					return;
				if (args[0] != null && args[1] != null) {
					//System.out.println(args[0] + "  :  " + args[1]);
					params.put(args[0], args[1]);
				}
			}
		}
	}
	
	public void extractPath()
	{
		paths = url.getPath().split("/");	
	}
	
//	abstract public void fllter();
	
}
